home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: How to tell if a file exists in C
- Date: Tue, 06 Feb 96 17:26:05 GMT
- Organization: none
- Message-ID: <823627565snz@genesis.demon.co.uk>
- References: <4eqkj6$ipo@charm.magnus.acs.ohio-state.edu> <m2pwbuvfb9.fsf@hawk.no>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <m2pwbuvfb9.fsf@hawk.no>
- jan-henrik.haukeland@fou.telenor.no "jan-henrik haukeland" writes:
-
- >Use the stat function, e.g.:
- >
- >#include <sys/stat.h>
- >#include <unistd.h>
- >
- >/* Check if file exists */
- >int fexist(char * filename)
- >{
- > struct stat buf;
- >
- > if (( stat (filename, &buf)) < 0)
- > return (FALSE);
- >
- > if (! S_ISREG(buf.st_mode)) {
- > return (NOT_A_REGULAR_FILE);
- > }
- >
- > return(TRUE);
- >}
-
- This function returns 3 distinct values. As such it does not return a
- voolean-like quantity. Therefore it is highly misleading to label two of
- those return values as TRUE and FALSE - you should find some more
- appropriate names.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-